{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4e8fa300",
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging\n",
    "def foo(s):\n",
    "    return 10 / int(s)\n",
    "\n",
    "\n",
    "def bar(s):\n",
    "    return foo(s) * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7e38eb33",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "ERROR:root:division by zero\n",
      "Traceback (most recent call last):\n",
      "  File \"C:\\Users\\10767\\AppData\\Local\\Temp\\ipykernel_16396\\2187031557.py\", line 3, in main\n",
      "    bar(\"0\")\n",
      "  File \"C:\\Users\\10767\\AppData\\Local\\Temp\\ipykernel_16396\\4190509365.py\", line 7, in bar\n",
      "    return foo(s) * 2\n",
      "           ^^^^^^\n",
      "  File \"C:\\Users\\10767\\AppData\\Local\\Temp\\ipykernel_16396\\4190509365.py\", line 3, in foo\n",
      "    return 10 / int(s)\n",
      "           ~~~^~~~~~~~\n",
      "ZeroDivisionError: division by zero\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "End\n"
     ]
    }
   ],
   "source": [
    "def main():\n",
    "    try: \n",
    "        bar(\"0\")\n",
    "    except Exception as e:\n",
    "        logging.exception(e)\n",
    "\n",
    "main()\n",
    "print(\"End\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bb9e4560",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def foo(s):\n",
    "    n = int(s)\n",
    "    if n == 0:\n",
    "        raise ValueError(\"invalid value: %s\" % s)\n",
    "    return 10 / n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1ff2a232",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "valueError!\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "invalid value: 0",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[6], line 7\u001b[0m\n\u001b[0;32m      5\u001b[0m         \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvalueError!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      6\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m\n\u001b[1;32m----> 7\u001b[0m bar()\n",
      "Cell \u001b[1;32mIn[6], line 3\u001b[0m, in \u001b[0;36mbar\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mbar\u001b[39m():\n\u001b[0;32m      2\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m----> 3\u001b[0m         foo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m0\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      4\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m      5\u001b[0m         \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvalueError!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "Cell \u001b[1;32mIn[3], line 4\u001b[0m, in \u001b[0;36mfoo\u001b[1;34m(s)\u001b[0m\n\u001b[0;32m      2\u001b[0m n \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(s)\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m n \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m----> 4\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minvalid value: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m s)\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m10\u001b[39m \u001b[38;5;241m/\u001b[39m n\n",
      "\u001b[1;31mValueError\u001b[0m: invalid value: 0"
     ]
    }
   ],
   "source": [
    "def bar():\n",
    "    try:\n",
    "        foo(\"0\")\n",
    "    except ValueError as e:\n",
    "        print(\"valueError!\")\n",
    "        raise\n",
    "bar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0c66b80f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo(s):\n",
    "    n = int(s)\n",
    "    assert n !=0, 'n is zero!'\n",
    "    return 10 /n\n",
    "def main():\n",
    "    foo('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5df6061b",
   "metadata": {},
   "outputs": [
    {
     "ename": "AssertionError",
     "evalue": "n is zero!",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAssertionError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[8], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m main()\n",
      "Cell \u001b[1;32mIn[7], line 6\u001b[0m, in \u001b[0;36mmain\u001b[1;34m()\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmain\u001b[39m():\n\u001b[1;32m----> 6\u001b[0m     foo(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m0\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "Cell \u001b[1;32mIn[7], line 3\u001b[0m, in \u001b[0;36mfoo\u001b[1;34m(s)\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfoo\u001b[39m(s):\n\u001b[0;32m      2\u001b[0m     n \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(s)\n\u001b[1;32m----> 3\u001b[0m     \u001b[38;5;28;01massert\u001b[39;00m n \u001b[38;5;241m!=\u001b[39m\u001b[38;5;241m0\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mn is zero!\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m      4\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m10\u001b[39m \u001b[38;5;241m/\u001b[39mn\n",
      "\u001b[1;31mAssertionError\u001b[0m: n is zero!"
     ]
    }
   ],
   "source": [
    "main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a95fe499",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
